package 因子分解和枚举.最接近的因数;

import java.util.Arrays;

/**
 * TODO
 *
 * @className: zjjdys
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-05-07 08:37
 **/
public class zjjdys {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(closestDivisors(8)));

        System.out.println(Arrays.toString(closestDivisors(123)));
        System.out.println(Arrays.toString(closestDivisors(999)));

        System.out.println(Arrays.toString(closestDivisors(1)));
        System.out.println(Arrays.toString(closestDivisors(2)));
    }
    public static int[] closestDivisors(int num) {
        System.out.println();
        int[] result1 = getYz(++num);
        int[] result2 = getYz(++num);
        System.out.println("result1 "+Arrays.toString(result1));
        System.out.println("result2 "+Arrays.toString(result2));
        System.out.println("result1 差"+Math.abs(result1[0]-result1[1]));
        System.out.println("result2 差"+Math.abs(result2[0]-result2[1]));
        return (Math.abs(result1[0]-result1[1])<=Math.abs(result2[0]-result2[1]))?result1:result2;
    }

    public static int[] getYz(int num){
        System.out.println("本次计算 "+num);
        int[] result = new int[2];
        for (int i = 1; i <= Math.sqrt(num); ++i) {
            if ((num) % i == 0){
                result[0] = i;
                result[1] = num / i;
                System.out.println(num+"/"+i+"="+(num/i));
            }
        }
        return result;
    }
}
